﻿using System;

namespace CardPlay.Model.CardModel
{
    public static class RankSequence
    {
        public static bool DontCare(Rank rank, Rank nextRank)
        {
            return true;
        }

        public static bool SameRank(Rank rank, Rank nextRank)
        {
            return rank == nextRank;
        }

        public static bool AdjacentRank(Rank rank, Rank nextRank)
        {
            return 
                (rank == Rank.King && nextRank == Rank.Ace) ||
                (rank == Rank.Ace && nextRank == Rank.King) ||
                Math.Abs(rank - nextRank) == 1;
        }

        public static bool AscendingRank(Rank rank, Rank nextRank)
        {
            return AscendingDifference(rank, nextRank) == 1;
        }

        public static bool DescendingRank(Rank rank, Rank nextRank)
        {
            return DescendingDifference(rank, nextRank) == 1;
        }

        public static int AscendingDifference(Rank rank, Rank nextRank)
        {
            var difference = nextRank - rank;
            return difference < 0 ? difference + CardFace.RanksPerSuit : difference;
        }

        public static int DescendingDifference(Rank rank, Rank nextRank)
        {
            return AscendingDifference(nextRank, rank);
        }
    }
}
